package net.awpspace.mobile.management.house;

import java.io.IOException;

import javax.microedition.midlet.MIDlet;

import net.awpspace.mobile.form.BaseForm;

import com.sun.lwuit.Button;
import com.sun.lwuit.Command;
import com.sun.lwuit.Container;
import com.sun.lwuit.Image;
import com.sun.lwuit.Label;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.layouts.CoordinateLayout;

public class HouseManagement extends BaseForm {

	private static String ADD = "Thêm người";
	private static String DELETE = "Xóa người";
	private static String VIEW = "Xem thông tin chi tiết";
	private static String SEARCH = "Tìm kiếm người";
	private static String STATISTIC = "Thống kê";

	private Command add;
	private Command delete;
	private Command view;
	private Command search;
	private Command statistic;
		
	private Container infor;
	
	private Image im_add;
	private Image im_delete;
	private Image im_view;
	private Image im_search;
	private Image im_statistic;
	
	
	public HouseManagement(MIDlet app, BaseForm parent) {
		super(app, parent);
		// TODO Auto-generated constructor stub
		setTitle("House Management");
		setLayout(new CoordinateLayout());		
		createCommand();
		infor();
		createImage();
		createMenu();
	}

	public void createImage(){
		try {
			im_add = Image.createImage("/housedata/add.png");
			im_delete = Image.createImage("/housedata/delete.png");
			im_view = Image.createImage("/housedata/view.png");
			im_search = Image.createImage("/housedata/search.png");
			im_statistic = Image.createImage("/housedata/statistic.png");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void createCommand() {
		add = new Command(ADD);
		delete = new Command(DELETE);
		view = new Command(VIEW);
		search = new Command(SEARCH);
		statistic = new Command(STATISTIC);
		addCommand(add, 0);
		addCommand(delete, 1);
		addCommand(view, 2);
		addCommand(search, 3);
		addCommand(statistic, 4);
	}

	public void infor() {
		infor = new Container();
		Label lbName = new Label("Chương trình quản lý nhà trọ");
		Label lb1 = new Label("SV: Phạm Hồng Kỳ");
		Label lb2 = new Label("Lớp: D09CNPM2");
		infor.addComponent(lbName);
		infor.addComponent(lb1);
		infor.addComponent(lb2);
		infor.setWidth(240);
		infor.setHeight(100);
		infor.setX(0);
		infor.setY(0);		
		addComponent(infor);
		
//		Style s = UIManager.getInstance().getComponentStyle("Button");
//		Style f = new Style();
//		f.setBgImage(background, true);
//		UIManager.getInstance().setComponentStyle("Form", f);
//		Style s;
//		s = new Style();
//		Font font = Font.createSystemFont(Font.FACE_PROPORTIONAL, Font.STYLE_ITALIC, Font.SIZE_SMALL);
//		s.setFont(font);
//		UIManager.getInstance().setComponentStyle("Button", s);
		
	}

	public void createMenu(){
		Button  btn_add = new Button(add);
		btn_add.setIcon(im_add);
		btn_add.setX(0);
		btn_add.setY(192);
		btn_add.setWidth(72);
		btn_add.setHeight(72);
		btn_add.getStyle().setBgTransparency(0, true);
		
		
		Button  btn_delete = new Button(delete);
		btn_delete.setIcon(im_delete);
		btn_delete.setX(84);
		btn_delete.setY(107);
		btn_delete.setWidth(72);
		btn_delete.setHeight(72);
		btn_delete.getStyle().setBgTransparency(0, true);
		
		Button  btn_view = new Button(view);
		btn_view.setIcon(im_view);
		btn_view.setX(84);
		btn_view.setY(192);
		btn_view.setWidth(72);
		btn_view.setHeight(72);
		btn_view.getStyle().setBgTransparency(0, true);
		
		Button  btn_search = new Button(search);
		btn_search.setIcon(im_search);
		btn_search.setX(169);
		btn_search.setY(192);
		btn_search.setWidth(72);
		btn_search.setHeight(72);
		btn_search.getStyle().setBgTransparency(0);
		
		Button  btn_statistic = new Button(statistic);
		btn_statistic.setIcon(im_statistic);
		btn_statistic.setX(84);
		btn_statistic.setY(267);
		btn_statistic.setWidth(72);
		btn_statistic.setHeight(72);
		btn_statistic.getStyle().setBgTransparency(0, true);
		
		addComponent(btn_add);
		addComponent(btn_delete);
		addComponent(btn_view);
		addComponent(btn_search);
		addComponent(btn_statistic);
		
	}
	protected void processCommand(ActionEvent e) {
		// TODO Auto-generated method stub
		AudioManager.getInstance().play(AudioManager.BUTTON);
		if (e.getCommand().equals(add)) {
			new AddMemberViewer(app, this).show();			
		} else if (e.getCommand().equals(delete)) {
			new DeleteMemberViewer(app, this).show();
		} else if (e.getCommand().equals(view)) {
			new MemberViewer(app, this).show();
		}
		else if (e.getCommand().equals(search)) {
			new SearchDialog(app, this).show();
		}
		else if (e.getCommand().equals(statistic)) {
			new Note(app, this).show();
		}
	}

}
